package com.team.cluedo.app;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.AdapterView.OnItemClickListener;

import com.team.cluedo.Game;
import com.team.cluedo.R;
import com.team.cluedo.app.utils.CluedoMenu;
import com.team.cluedo.app.utils.ImageAdaptater;

public class PlayerFiche extends Activity {
	
	private static final int CARD_WIDTH = 85;
	private static final int CARD_HEIGHT = 100;
	int positionPerso;
	int positionArme;
	int positionPiece;
	Intent defineIntent;
	Activity activity;
	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		return CluedoMenu.onCreateOptionsMenu(menu, this);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return CluedoMenu.onOptionsItemSelected(item, this);
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

	    setContentView(R.layout.threegalleries);
	    
	    activity = this;
	    
	    Gallery gPerso = (Gallery) findViewById(R.id.gallerycharacter);
	    gPerso.setAdapter(new ImageAdaptater(this,Game.cluedo.ficheOfCharacter, CARD_WIDTH, CARD_HEIGHT));

	    gPerso.setOnItemClickListener(new OnItemClickListener() {
	        public void onItemClick(AdapterView parent, View v, int position, long id) {
	        	if(positionPerso == position){
	        		Game.cluedo.ficheOfCharacter[position].setSelect();
	        		defineIntent = new Intent(activity,PlayerFiche.class);
	        		activity.startActivity(defineIntent);
	        		activity.finish();
	        		
	        	}
	        	positionPerso = position;
	        }
	    });
	    
	    Gallery gWeapons = (Gallery) findViewById(R.id.galleryweapon);
	    gWeapons.setAdapter(new ImageAdaptater(this,Game.cluedo.ficheOfWeapon, CARD_WIDTH, CARD_HEIGHT));

	    gWeapons.setOnItemClickListener(new OnItemClickListener() {
	        public void onItemClick(AdapterView parent, View v, int position, long id) {
	        	if(positionArme == position){
	        		Game.cluedo.ficheOfWeapon[position].setSelect();
	        		defineIntent = new Intent(activity,PlayerFiche.class);
	        		activity.startActivity(defineIntent);
	        		activity.finish();
	        	}
	        	positionArme = position;
	        }
	    });
	    
	    Gallery gPiece = (Gallery) findViewById(R.id.galleryroom);
	    gPiece.setAdapter(new ImageAdaptater(this,Game.cluedo.ficheOfRoom, CARD_WIDTH, CARD_HEIGHT));

	    gPiece.setOnItemClickListener(new OnItemClickListener() {
	        public void onItemClick(AdapterView parent, View v, int position, long id) {
	        	if(positionPiece == position){
	        		Game.cluedo.ficheOfRoom[position].setSelect();
	        		defineIntent = new Intent(activity,PlayerFiche.class);
	        		activity.startActivity(defineIntent);
	        		activity.finish();
	        	}
	        	positionPiece = position;
	        }
	    }); 
	}
}
